<html>
<head><meta charset="utf-8"><title>Cargo and concurrency · t-cargo · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/index.html">t-cargo</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cargo.20and.20concurrency.html">Cargo and concurrency</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="222790156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cargo%20and%20concurrency/near/222790156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Arlie Davis <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cargo.20and.20concurrency.html#222790156">(Jan 14 2021 at 21:55)</a>:</h4>
<p>Is it safe to run more than 1 instance of Cargo, if they use different <code>--target-dir</code>?  I'm thinking specifically about the cached crates that are stored in <code>$CARGO_HOME</code>, and the copy of the <a href="http://crates.io">crates.io</a> index. </p>
<p>In other words, if I have a single huge source tree, and a dozen <code>Cargo.toml</code> workspaces (each of which contains N crate members), can I safely run <code>cargo --target-dir .../some_dir</code> for each of these workspaces?</p>
<p>It's not an option to combine them into one single Cargo invocation.</p>



<a name="222790332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cargo%20and%20concurrency/near/222790332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cargo.20and.20concurrency.html#222790332">(Jan 14 2021 at 21:56)</a>:</h4>
<p>Cargo uses filesystem locks to avoid clobbering concurrent processes IIRC</p>



<a name="222790335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cargo%20and%20concurrency/near/222790335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cargo.20and.20concurrency.html#222790335">(Jan 14 2021 at 21:56)</a>:</h4>
<p>so you should be fine</p>



<a name="222790644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cargo%20and%20concurrency/near/222790644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Arlie Davis <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cargo.20and.20concurrency.html#222790644">(Jan 14 2021 at 21:59)</a>:</h4>
<p>Good to hear. Does it use different locking scopes for $CARGO_HOME vs. the target dir?</p>



<a name="222791299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cargo%20and%20concurrency/near/222791299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cargo.20and.20concurrency.html#222791299">(Jan 14 2021 at 22:04)</a>:</h4>
<p>I think so?</p>



<a name="222795757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cargo%20and%20concurrency/near/222795757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cargo.20and.20concurrency.html#222795757">(Jan 14 2021 at 22:39)</a>:</h4>
<p>Yes we strive to make cargo safe to concurrently run at all times. This isn't heavily tested, however, so there may be a bug here or there (we haven't seen one in a long time though)</p>



<a name="222795918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cargo%20and%20concurrency/near/222795918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cargo.20and.20concurrency.html#222795918">(Jan 14 2021 at 22:40)</a>:</h4>
<p>The actual parallelism you'll get from concurrent cargo invocations, however, is quite poor. There are separate locks for the home and target directory, though. Basically cargo executions in parallel with a shared home dir oonly synchronize during the download phase. Shared cargo invocations with the same target directory, however, are entirely serialized</p>



<a name="222796158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cargo%20and%20concurrency/near/222796158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Arlie Davis <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cargo.20and.20concurrency.html#222796158">(Jan 14 2021 at 22:42)</a>:</h4>
<p>In the near term, my priority is correctness and reliability. So this sounds good.</p>



<a name="222796318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cargo%20and%20concurrency/near/222796318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cargo.20and.20concurrency.html#222796318">(Jan 14 2021 at 22:44)</a>:</h4>
<p>Ah ok that should work well then! That matches with how we approach it which is that we want everything to primarily work first, and afterwards we try to increase actual parallelism where we can</p>



<a name="222796329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cargo%20and%20concurrency/near/222796329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cargo.20and.20concurrency.html#222796329">(Jan 14 2021 at 22:44)</a>:</h4>
<p>but if you run into any issues please let us know!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>